package com.handydata.antifraud.rule.funcs;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;

import com.handydata.antifraud.to.RiskInputTO;
import com.handydata.antifraud.to.RiskMiddleTO;
import com.handydata.antifraud.to.RiskOutputTO;

/**
 * 计算同盾分和模型分
 */
@Slf4j
@Component
public class CalcYouBenModelScore implements Calculate {
    
    @Override
    public void doCalc(RiskInputTO riskInputTO, RiskMiddleTO riskMiddleTO,RiskOutputTO riskOutputTO) {
        log.info("start calc {} 同盾分和模型分coreOfDataYouBen{} riskScore{}", RULE_CALC_TEXT,riskInputTO.getScoreOfDataYouBen(),riskMiddleTO.getRiskScore());
		Double tongdun_model_score = 0D;
		double tongdun_score = riskInputTO.getScoreOfDataYouBen();
        if (tongdun_score < 30)
        tongdun_model_score = tongdun_score*10;
        else if (tongdun_score < 70)
        tongdun_model_score = ((tongdun_score-30)/(70-30))*(650-300)+300;
        else if(tongdun_score < 80)
        tongdun_model_score = ((tongdun_score-70)/(80-70))*(800-650)+650;
        else
        tongdun_model_score = ((tongdun_score-80)/(1000-80))*(1000-800)+800;

        Integer riskscore=riskMiddleTO.getRiskScore();
        if(riskscore==null)
                    riskscore=0;
        if(tongdun_model_score>riskscore){
            riskOutputTO.setRiskScore(tongdun_model_score.intValue());
        }else {
            riskOutputTO.setRiskScore(riskscore);
        }

        log.info("finish {}同盾分和模型分{}", RULE_CALC_TEXT,riskscore);
    }
}
